<%@page import="cn.lily.com.enviroment.Enviroment"%>
<%@page import="app.portal.dao.Pw_mer_infoBean"%>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="cn.lily.inst.web.frames.FrameConfig" %>
<%@ page import="cn.lily.web.util.context.WebContext" %>
<%@ page import="cn.lily.esb.context.AuthEntity" %>
<%@ page import="cn.lily.com.container.ram.ApplicationContext"%>
<%@page import="cn.lily.com.db.sql.DBManager"%>
<%@page import="app.portal.dao.Pt_app_infoBean"%>
<%@ page import="app.portal.util.UtilMethod"%>
<%@page import="app.portal.util.EnumValue"%>
<%@page import="cn.lily.com.db.DBFactory"%>
<%@page import="cn.lily.com.db.container.reader.DataTable"%>
<%@page import="cn.lily.com.lang.VerifyData"%>
<%@page import="cn.lily.web.util.config.WebSetting"%>
<%@ page import="cn.lily.com.configure.util.ESBSetting"%>
<%@ include file="/frames/logbegin.jsp" %>
<%
String appid=WebSetting.getString("single_id");
	String skinName = "";
  String contextPath = "";
  AuthEntity authEntity = (AuthEntity) session.getAttribute(WebContext.LOG_AUTH_CONTEXT);
  if (authEntity != null) {
  	skinName = authEntity.getSkinName();
  	contextPath = authEntity.getContextPath();
  }
  FrameConfig.setContextPath(contextPath);
  authEntity.getOperEntity().setAppID(appid);
  ApplicationContext.setAuthEntity(request.getSession().getId(), authEntity);
 
  //设置应用编号
  authEntity.getOperEntity().setAppID(appid);
  
  String baseSql= "";
  if("9999".equals(authEntity.getOperatorId())){
	  baseSql=" select * from ${schema}.PW_APP_MODEL where pw_app_id='"+appid+"' order by view_idx ";
  }
  else if(EnumValue.OPER_TYP_1.equals(authEntity.getOperEntity().getOperType())){
	  baseSql=" select * from ${schema}.PW_APP_MODEL where pw_app_id='"+appid+"' order by view_idx ";
  }
  else{
	  baseSql=" select * from ${schema}.PW_APP_MODEL where pw_app_id='"+appid+"' and MODE_ID in ( select a.MODE_ID from ${schema}.PW_ROLE_RES a ,${schema}.PW_OPER_ROLE b where a.ROLE_ID=b.ROLE_ID and b.oper_key='"+authEntity.getOperatorId()+"') order by view_idx ";
	  
  }
  
  DBManager dbManager=DBFactory.getActionDB();
  DataTable menuTable=dbManager.executeQueryTable(baseSql);
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  <meta charset=utf-8>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title><%=FrameConfig.getAppName()%></title>
  <link href="/<%=ESBSetting.getString("appCode")%>/public/style/skin_bootstrap/bootstrap-3.3.0/bootstrap.css" rel="stylesheet" media="screen">
  <link href="/<%=ESBSetting.getString("appCode")%>/public/font/awesome/font-awesome-4.7.0.css" rel="stylesheet">
  <link href="<%=FrameConfig.getCSSPath("app.css") %>" rel="stylesheet" />

</head>
<body>
  <div id="main-left">
    <div class="accordion" id="accordion2" >
    	
        <%
        while(menuTable.next()){
          %>
          <div class="accordion-group menu-pattern">
          <div class="accordion-heading menu-first"><a class="accordion-toggle" data-toggle="collapse" data-target="#menu-<%=menuTable.getString("mode_id") %>" data-parent="#accordion2"><%=menuTable.getString("mode_nam")%></a></div>
          <%
          String itemsql="";
          if(EnumValue.OPER_TYP_1.equals(authEntity.getOperEntity().getOperType())) {
        	  itemsql=" SELECT a.MENU_ID,a.APP_ID,a.MENU_NAM,b.menu_src FROM ${schema}.PW_APP_MENU a,PW_APP_MENU_INFO b "
          				+" WHERE a.MENU_ID=b.MENU_ID and a.MODE_ID='"+menuTable.getString("mode_id")+"' order by a.view_idx ";
          }else{
        	  itemsql="SELECT a.MENU_ID,a.APP_ID,a.MENU_NAM,b.menu_src FROM ${schema}.PW_ROLE_RES a,PW_APP_MENU_INFO b,PW_OPER_ROLE c,pw_role d "
        				+" WHERE a.MENU_ID=b.MENU_ID and a.role_id=c.role_id and c.role_id=d.role_id and d.status='1' and c.oper_key='"+authEntity.getOperatorId()+"' and a.MODE_ID='"+menuTable.getString("mode_id")+"' order by a.view_idx ";
		  }
          DataTable itemTable = DBFactory.getActionDB().executeQueryTable(itemsql);
          if(itemTable.getRecordCount()>0){
            %>
            <div id="menu-<%=menuTable.getString("mode_id") %>" class="accordion-body collapse">
                <%
                while(itemTable.next()){
  	              //获取某个系统的url缓存
  	            	String url=(String)session.getAttribute(itemTable.getString("app_id"));
  	            	if(url==null ||"".equals(url)){
  	            		url=UtilMethod.getUrl(itemTable.getString("app_id"));
  	            		if(!"0".equals(url)) {        
  	            			session.setAttribute(itemTable.getString("app_id"), url);
  	            		}else {           			
  	            			url = request.getContextPath();
  	            		}
  	            	}
                    String menuSrc="";
                    if(itemTable.getString("menu_src").indexOf("http://")<0){
                  	  if(itemTable.getString("menu_src").indexOf("?")>0) {                 		  
                      	  menuSrc=url+itemTable.getString("menu_src")+"appid="+authEntity.getOperEntity().getAppID()+"&sessionID="+session.getId();                			                    		  
                  	  }else{                  		  
                      	menuSrc=url+itemTable.getString("menu_src")+"?appid="+authEntity.getOperEntity().getAppID()+"&sessionID="+session.getId();                  			                    		  
                  	  }
                    }else{
                  	  if(itemTable.getString("menu_src").indexOf("?")>0) {
                  		  menuSrc=itemTable.getString("menu_src")+"appid="+authEntity.getOperEntity().getAppID()+"&sessionID="+session.getId();
                  	  }else{
                  		  menuSrc=itemTable.getString("menu_src")+"?appid="+authEntity.getOperEntity().getAppID()+"&sessionID="+session.getId();
                  	  }
                    }
                  %>
                  <div class="accordion-inner menu-second"><a href="<%=menuSrc %>" target="contentFrame" class="menu-second-a"><%=itemTable.getString("MENU_NAM") %></a></div>
                  <%
                }
                %>
            </div>
               <%
          }
          %>
          </div>
        <%
        }
      dbManager.free();
      %>
     <%@ include file="/frames/logend.jsp" %>
    </div>
    
  </div>
  <div id="main-right">
    <iframe name="contentFrame" src=""  frameborder="0" height="100%" width="100%"></iframe>
  </div>

  <script src="<%=FrameConfig.getBaseJsUrl() %>/common/jquery-1.9.1.min.js"></script>
  <script src="/<%=ESBSetting.getString("appCode")%>/public/js/skin_bootstrap/bootstrap-3.3.0/bootstrap-3.3.0.js"></script>
  <script src="<%=FrameConfig.getJsUrl("app.js")%>"></script>
  <script type="text/javascript" language="javascript"> 
  $(function(){
  	$(".menu-first a").hover(function(){
		$(this).parent().parent().parent().children().children(".menu-firstv").removeClass("menu-firstv");
		$(this).parent().addClass("menu-firstv");
	});
	$(".menu-first a").click(function(){
		$(this).parent().parent().parent().children().children(".menu-firstv").removeClass("menu-firstv");
		$(this).parent().addClass("menu-firstv");
	});
  	$(".menu-second a").hover(function(){
		$(this).parent().parent().parent().parent().children().children(".menu-firstv").removeClass("menu-firstv");
		$(this).parent().parent().prev().addClass("menu-firstv");
  	});
  	$(".menu-second a").click(function(){
  		$(this).parent().parent().parent().parent().children().children(".menu-firstv").removeClass("menu-firstv");
  		$(this).parent().parent().parent().parent().children().children().children(".menu-second-selected").removeClass("menu-second-selected");
	  	$(this).parent().parent().prev().addClass("menu-firstv");
	  	$(this).parent().addClass("menu-second-selected");
  	});
  	
  	
  })
  </script>
</body>
</html>

